/**
 * 字段ID前缀
 * @type String
 */
biAnaly.COLUMN_BTN_ID_PREFIX = 'column_btn_';

/**
 * 旋转后的数值值
 * @type String
 */
biAnaly.SIGMA_VALUE = 'sigma_value';
/**
 * 旋转后的数值名
 * @type String
 */
biAnaly.SIGMA_NAME = 'sigma_name';

/**
 * 图形Anychart属性编辑器
 * @class biAnaly.PicEditPanel
 * @extends Ext.Panel
 * @author chenzhuangwei
 */

var xAsix = null;   //声明全局 轴字段
var columnDrillTooltip;
var drillFlag = 1;  //钻取标识;1：钻取，2：不钻取。
var columnButtonText = "";    //按钮显示内容
var columnButtonAttrText = "";    //按钮显示钻取路径
var columnBtnNamePath = ""; //namePath

biAnaly.PicEditPanel = Ext.extend(Ext.Panel, {
	layout:'column',
	serieCfg : {
		measure  : biAnaly.SIGMA_VALUE,	//指标值		
		topAxis  : [],					//竖轴 （序列）
		leftAxis : [],					//横轴 （分类）
		numerics : []					//数值
	},
	columnCfgTooltip : null,
	columnEditTooltip : null,
	columnFilterTooltip : null,
	columnDrillTooltip : null,
	listeners : {
		bodyresize : function(panel, width, height ){
			var length = panel.items.getCount();
			for(var i = 0 ; i < length;i++){
				var c = panel.items.itemAt(i);
				c.setHeight(height/2);
			}
		},
		afterrender : function( panel ) {
			if(panel.columnEditTooltip == null) {   //新建 编辑panel,用作图例字段编辑所调用
				panel.columnEditTooltip = new biAdhocNs.UXToolTipWindow({ 
					parentBtn : null,
					title : columnpanel.title_Edit,//编辑
					autoHide : false,
					closable : true,
					hidden : true,
					draggable : true,
					width : 350,
					bodyStyle:'padding:10px',
					layout: 'form',
					items : [{
					 	id:"text_lengend_id", 
						xtype : 'textfield',
						fieldLabel : columnpanel.fieldLabel_customName,//自定义名称
						name:'customName'
					},{
						layout : 'hbox',
						border : false,
						layoutConfig: {
							padding:'5',
						    align : 'middle',
						    pack  : 'center'
						},
						defaults:{margins:'0 10 0 10'},
						items : [{
							xtype : 'button',
							text : columnpanel.text_save,//保存
							handler : function(){
								var tooltip = panel.columnEditTooltip;
								var text_lengend_value=Ext.getCmp('text_lengend_id').getValue();
								tooltip.doSave(text_lengend_value);
								tooltip.hide();
							}
						}, {
							xtype : 'button',
							text : columnpanel.text_cancel,//取消
							handler : function(){
								panel.columnEditTooltip.hide();
							}
						}]
					}],
					setParentBtn : function( comp ) {
						this.parentBtn = comp;
						if( comp ){
							Ext.getCmp('text_lengend_id').setValue(comp.text? comp.text : '');
						}
					},
					doSave : function( object ) {
						this.parentBtn.setText_lengdend(object);
						this.parentBtn.syncSize();
						this.parentBtn.ownerCt.doLayout();
						this.setParentBtn(null);
					}
				});
				panel.columnEditTooltip.hide();
			}
			
			if(panel.columnCfgTooltip == null){
				panel.columnCfgTooltip = new biAdhocNs.UXToolTipWindow({ 
					parentBtn : null,
					title : columnpanel.title_valueConfig,//值字段配置
					autoHide : false,
					closable : true,
					hidden : true,
					draggable : true,
					width : 360,
					bodyStyle:'padding:10px',
					layout: 'form',
					items : [{
						xtype:'tabpanel',
				        activeTab: 0,
			            height:300,
			            defaults:{bodyStyle:'padding:10px'},
			            items:[{
			                title:columnpanel.title_summaryWay,//汇总方式
			                defaults: {width: 320, height : 270},
			                defaultType: 'label',
			                items: [{
			                    text: columnpanel.text_valueSummaryWay//'值字段汇总方式'
			                },{
			                    text: columnpanel.text_selSumData//'选择用于汇总所选字段数据的计算类型'
			                },{
			                	xtype : 'multiselect',
			                	name : 'multiselect',
			                	allowBlank: false,
					            minSelections: 1,
					            maxSelections: 1,
			                	valueField : 'value',
			                	displayField : 'disp',
			                	store : new Ext.data.ArrayStore({
	                				fields: ['value','text','disp'],
	                				data: [
	                				    ['sum',columnpanel.text_sum,columnpanel.disp_sum],
	                					['count', columnpanel.text_count,columnpanel.disp_count],
			                			['avg', columnpanel.text_avg,columnpanel.disp_avg],
			                			['max',columnpanel.text_max,columnpanel.disp_max],
			                			['min',columnpanel.text_min,columnpanel.disp_min]
			                		]
	            				}),
			                	getSelected : function(){
			                		return this.view.getSelectionCount() == 1 ?
			                			{
											name : this.getValue('value'),
											description : this.getValue('text')
										} : null ;
			                	}
			                }]
			            },{
			            	title:columnpanel.title_customSummaryWay,//自定义汇总方式
			                defaultType: 'label',
			                items: [{
			                	xtype:'fieldset',
			        			title: columnpanel.title_expression,//表达式 
			        			items: [{
			        				xtype: 'textarea',
			        				width: 180,
			        				emptyText: columnpanel.emptyText_enter,//'请输入'
			        				hideLabel : true,
			        				id:'customStyle'
			        			}]
			                },{
			                	xtype:'fieldset',
			        			title: columnpanel.title_example,//'示例' 
			        			html: '1. sum ( ' + columnpanel.en_column + ' )/100 as ' + columnpanel.en_column + '<br>' +  
			        				  '2. case when count ( ' + columnpanel.en_column + '  )/100 ... then ... when ... then ... else ... end  as ' + columnpanel.en_column 
        					}]
			            },{
			            	title:columnpanel.title_unit,//'单位'
			                defaultType: 'label',
			                items: [{
			                	xtype:'fieldset',
			        			title: columnpanel.title_unit, //'单位'
			        			height:100,
			        			items :[{
			        				xtype: 'textfield',
			        				emptyText: columnpanel.emptyText_enter,
			        				hideLabel : true,
			        				id:'dataUnit'
			        			}]
			                }]
			            },{
			            	title:columnpanel.title_accuracy,//'精度'
			                defaultType: 'label',
			                items: [{
			                	xtype:'fieldset',
			        			title: columnpanel.title_accuracy, //'精度'
			        			height:100,
			        			columnWidth: 0.5,
			        			items :[{
			        				xtype: 'textfield',
			        				emptyText: '2',
			        				hideLabel : true,
			        				id:'decimalPre'
			        			}]
			                }]
			            }]
					},{
						layout : 'hbox',
						border : false,
						layoutConfig: {
							padding:'5',
						    align : 'middle',
						    pack  : 'center'
						},
						defaults:{margins:'0 10 0 10'},
						items : [{
							xtype : 'button',
							text : columnpanel.text_save,//'保存'
							handler : function(){
								var tooltip = panel.columnCfgTooltip;
								var ms = tooltip.findByType('multiselect')[0];
								if(!ms.getSelected()){
									Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_selAType);//'请选择一个类型'
									return ;
								}
								
								var customStyle = Ext.getCmp('customStyle').getValue();
								var dataUnit = Ext.getCmp('dataUnit').getValue();
								var decimalPre = Ext.getCmp('decimalPre').getValue();
								tooltip.doSave(ms.getSelected(), customStyle, dataUnit, decimalPre);
								tooltip.hide();
							}
						},{
							xtype : 'button',
							text : columnpanel.text_cancel,//取消
							handler : function(){
								panel.columnCfgTooltip.hide();
							}
						}]
					}],
					setParentBtn : function( comp ){
						this.parentBtn = comp;
						if( comp ){
							//this.items.itemAt(0).setText('源名称：' + comp.attributes.cName);
							var ms = this.findByType('multiselect')[0];
							var nameValue = comp.aggregate.name;
							if(comp.attributes.customStyle != null ) {
								nameValue = "sum";
								this.parentBtn.aggregate.name = "sum";
							}
							ms.setValue(comp.aggregate.name ? nameValue : '');
							Ext.getCmp('dataUnit').setValue(comp.attributes.dataUnit? comp.attributes.dataUnit : '');
							Ext.getCmp('customStyle').setValue(comp.attributes.customStyle? comp.attributes.customStyle : '');
							Ext.getCmp('decimalPre').setValue(comp.attributes.decimalPrecision? comp.attributes.decimalPrecision : '');
						}
					},
					doSave : function( object, customStyle, dataUnit, decimalPre){
						this.parentBtn.attributes.dataUnit = dataUnit;
						this.parentBtn.attributes.decimalPrecision = decimalPre;
						this.parentBtn.attributes.customStyle = customStyle;
						this.parentBtn.setAggregate(object);
						this.parentBtn.updateCompText();
						this.parentBtn.syncSize();
						this.parentBtn.ownerCt.doLayout();
						this.setParentBtn(null);
					}
				});
				panel.columnCfgTooltip.hide();
			}

			if(biAdhocNs.conditionFilterObj == null) {
				biAdhocNs.conditionFilterObj = new biAdhocNs.ConditionFilter();
				// biAdhocNs.conditionFilterObj.initFilterTooltip();
			}
			if(columnDrillTooltip == null){						
				panel.columnDrillTooltip = new Ext.Window({
					title : columnpanel.title_drillPathSel,//'钻取路径选择'
					autoHide : false,
					closable : false,
					hidden : true,
					draggable : true,
					width : 600,
					html : null,
					target : null,
					gird : null,
					items : [],
					listeners : {
						beforeshow : function(tip) { // 展示前清空里面所有对象
							var len = tip.items.length;
							if (len > 0) {
								tip.removeAll(true);
								tip.doLayout();
							}
						},
						show : function(tip) { // 展示时把对象加进去
							if (tip.grid != null) {
								tip.add(tip.grid);
								tip.doLayout();
							}
						}
					}
				}).hide();
			}
		}

	},
	/**
	 * 设置字段状态，字段被选中或者删除选中状态时调用
	 * @param {} node 字段
	 * @param {} status 状态
	 */
	setColumnStatus : function(node,status,fieldName){
		var id = node.attributes.id;
		if(fieldName!=null&&fieldName!=''){
			columnPanel = this.findById(fieldName);
			columnPanel.addColumn(node.attributes, columnPanel);
			return;
		}
		if(status && this.isNotExistComp(biAnaly.COLUMN_BTN_ID_PREFIX + id)){
			//维加入到 轴字段 其他类型默认加入到 ∑数值 容器
			// var columnPanel = (node.attributes.colType == biAdhocNs.COLTYPE_DEMENSION 
			// 	? this.findById('axis-column')
			// 	: this.findById('numerical'));
			var columnPanel;
			var colType = node.attributes.colType;
			if(colType == biAdhocNs.COLTYPE_DEMENSION) {
				columnPanel = this.findById('axis-column');
			} else if(colType==biAdhocNs.COLTYPE_STAT_MON || 
					colType==biAdhocNs.COLTYPE_STAT_CIT) {
				columnPanel = this.findById('report-filter');
			} else {
				columnPanel = this.findById('numerical');
			}
			//检查是否可添加
			if(columnPanel.isCanAddColumn()) {
				columnPanel.addColumn(node.attributes, columnPanel);
			} else {//通过打勾添加，添加失败需要把勾去了
				Ext.getCmp('picturetree').setToggleCheck(id, false);
			}
		}

		if(!status){
			var comp = this.findById(biAnaly.COLUMN_BTN_ID_PREFIX + id);
			if(comp) comp.removeSelf();
			var compn = this.findById("sigma-number-btn" + biAnaly.COLUMN_BTN_ID_PREFIX + id);
			if(compn) compn.removeSelf();
		}
	},
	/**
	 * 是否不存在该组件，不存在返回 true
	 */
	isNotExistComp : function(id){
		return this.findById(id) == null;
	},
	/**
	 * 清空所有字段
	 */
	cleanAllColumn : function(){
		var axisPanel = this.findById('axis-column');
		axisPanel.removeAll(true);
		var numerical = this.findById('numerical');
		numerical.removeAll(true);
		var legend = this.findById('legend-column');
		legend.removeAll(true);
		//this.initSeriesConfig();//初始化配置
	},
	getSelectList : function(){
		var SELECT_LIST = {
			DESC : columnpanel.desc_outputFieldInfo,//'输出字段信息'
			SELECT_FIELDS : []
		};
		var columns = this.findAllColumnBtn();
		for(var i = 0 ;i < columns.length ; i++ ){
			SELECT_LIST.SELECT_FIELDS.push(columns[i].getSelectField());
		}
		return SELECT_LIST;
	},
	getGroupByClause: function(){
		var GROUP_BY_CLAUSE = {
			DESC : columnpanel.desc_groupByInfo,//'分组语句相关信息'
			GROUP_COLUMNS : [],
			HAVING_CONDITIONS : [{}]//分组条件,目前不支持
		};
		
		var columns = this.findAllColumnBtn();
		for(var i = 0 ;i < columns.length ; i++ ){
			if( columns[i].isAggregate == '0' )
				GROUP_BY_CLAUSE.GROUP_COLUMNS.push(columns[i].getGroupBy());
		}
		return GROUP_BY_CLAUSE;
	},
	/**
	 * 获取用于后台分块的维度信息
	 */
	getDimens4Blocking : function(){
		var list = [];
		//设置维度信息
		var c1 = Ext.getCmp('axis-column').findByType('columnbutton');
		var c2 = Ext.getCmp('legend-column').findByType('columnbutton');
		var columns = c1.concat(c2);
		for(var i = 0 ;i < columns.length ; i++ ){
			var attr = columns[i].attributes;
			if( attr.table ){//排除数值字段
				var suffix = attr.table.tablePartType == 1? '_'+this.getMonth():'';
				list.push({
					columnId	: attr.id,			//加入用于钻取处理
					tableName 	: attr.table.tableName + suffix,
					columnName 	: attr.name,
					dataType 	: attr.dataType,			// 数据类型[数字:NUMBER;字符:VARCHAR]
					tableAsName : attr.table.tableAsName,
					columnCName : attr.cName
				});				
			}
		}
		return list;
	},
	/**
	 * 获取分块配置信息
	 */
	getBlock : function(){
		var dimens = this.getDimens4Blocking();
    	//传到后台数据
        var block = {
        	calculate	: 'true',			//分块信息的计算，第一次加载时计算，提高性能
			activeBlock : 1,				//当前块
			totalBlocks : 0,				//总块数
			blockSize	: 50,				//一块数据的维度数，默认50，会在计算后进行修改
			dimensList 	: dimens			//维配置
        };
        return block;
	},
	/**
	 * 如果有钻取则修改分块相关信息，正确分块
	 * @param {} block
	 * @param {} drill
	 */
	resetBlockByDrill : function(block , drillList){
		if(block && drillList){
			//钻取条件：分块时需要对每个钻取链的钻取点作为查询条件进行分块
			block.drillCondition = {};
			
			//迭代每条钻取链、处理相关得钻取分块信息
			for(var i = 0 ; i < drillList.length ; i++){
				var drill = drillList[i];
				//迭代需进行分块的字段，替换成钻取后的字段
				for(var i = 0 ;i < block.dimensList.length ; i++){
					var c = block.dimensList[i];
					if(c.columnId == drill.origNode.columnId){
						//分块字段替换成钻取后的字段
						c.columnName = drill.drillNode.columnName;
						c.columnCName = drill.drillNode.nodeName;
						break;
					}
				}
				//加入钻取条件
				if(drill.preDrillNode && drill.value){
					block.drillCondition[drill.preDrillNode.columnId] =  drill.value;
				}
			}
		}
		
	},
	getFromClause : function() {
		var node = this
				.getNodeById(biAdhocNs.TableTreePanel.changeId);
		var mainTable = {
			"TABLE_ID" : node.attributes.tableID,
			"TABLE_NAME" : node.attributes.name,
			"TABLE_CNAME" : node.text,
			"DEF_CONDITION" : node.attributes.defCondition,
			"DATA_AREA_CONDITION" : node.attributes.dataAreaCondition,
			"AS_NAME" : node.attributes.asName,
			"TABLE_TYPE" : "0",
			"POSITION" : [],
			"PART_TYPE" : node.attributes.partType
		};
		var refTable = [];
		var _fromClause = {};
		_fromClause.MAIN_TABLE = mainTable;
		_fromClause.REF_TABLES = refTable;
		return _fromClause;// 由表管理提供
	},
	getJoinTableClause : function(id) {
		var array;
		var xnodeInfo = null;
		if (id != null && id != '') {
			// 取得所有节点
			var childNodes = Ext.getCmp('picturetree').root.childNodes; 
			for (var i = 0; i < childNodes.length; i++) {
				if (childNodes[i].findChild('name', id) != null) {
					xnodeInfo = childNodes[i].findChild('name', id);
				}
			}
			/*xnodeInfo = Ext.getCmp('picturetree').getNodeById(
					biAdhocNs.TableTreePanel.changeId)
					.findChild('id', id);*/
		}
		array = Ext.getCmp('axis-column').items.items;
		var xClause = {};// 维度字段
		for (var i = 0; i < array.length; i++) {
			// if (node.attributes.colType == 1) {
			var node = xnodeInfo == null ? array[i] : xnodeInfo;
			xClause.id = node.attributes.id;
			xClause.name = node.attributes.name;
			xClause.cName = node.attributes.cName;
			xClause.columnId = node.attributes.columnId;
			xClause.dataType = node.attributes.dataType;
			xClause.priority = node.attributes.priority;
			xClause.tableId = node.attributes.tableId;
			xClause.text = node.attributes.text;
			xClause.colType = node.attributes.colType;
			xClause.tableName = node.attributes.tableName;
		}
		return xClause;// 由表管理提供
	},
	getReportFilter : function(CnodeId) {
		var xnodeInfo = null;
		var items = Ext.getCmp('report-filter').items.items;
		var filter = new Array(); // 报表筛选
		var cFields = {};
		for (var i = 0; i < items.length; i++) {
			var node = items[i];
			filter.push({
				"columnId" : node.attributes.columnId, // 字段id
				"tableId" : node.attributes.tableId, // 表id
				"name" : node.attributes.name, // 字段名字
				"operator" : node.opChar, // 操作符
				"value" : node.avalue, // 条件值
				"paramType" : node.parameterType,
				"defaultValue" : node.avalue,
				"paramName" : node.attributes.cName,
				"colType" : node.attributes.colType,
				"tableName" : node.attributes.tableName
			});
		}
		if (CnodeId != null && CnodeId != '') {
			// 取得所有节点
			var childNodes = Ext.getCmp('picturetree').root.childNodes; 
			for (var i = 0; i < childNodes.length; i++) {
				if (childNodes[i].findChild('name', CnodeId[1]) != null) {
					xnodeInfo = childNodes[i].findChild('name', CnodeId[1]);
				}
			}
			/*xnodeInfo = Ext.getCmp('picturetree').getNodeById(
					biAdhocNs.TableTreePanel.changeId)
					.findChild('id', CnodeId[1]);*/
			filter.push({
				"columnId" : xnodeInfo.attributes.columnId, // 字段id
				"tableId" : xnodeInfo.attributes.tableId, // 表id
				"name" : xnodeInfo.attributes.name, // 字段名字
				"operator" : "=", // 操作符
				"value" : CnodeId[0], // 条件值,点击区域字段对应的英文名
				"paramType" : "valuePara",
				"defaultValue" : CnodeId[0],
				"paramName" : xnodeInfo.attributes.cName,
				"colType" : xnodeInfo.attributes.colType,
				"tableName" : xnodeInfo.attributes.tableName
			});
		}
		cFields.CONDITION = filter;
		return cFields;
	},
	/**
	 * where 条件
	 * @return {}
	 */
	getWhereClause: function(){
		return [];
	},
	getOrderByClause: function(){
		var numerical = this.findById('numerical');
		var first = numerical.items.first();
		//图形分析默认按第一个排序
		return first ? [{
			ID : "1",
			NODE_TYPE : "",
			EXP_VALUE : first.attributes.name,
			EXP_CVALUE : "",
			TABLE_NAME : "",
			FIELD_NAME : "",
			SORT_TYPE : "DESC",
			PART_TYPE : "0"
		}] : [];
	},
	/**
	 * 获取y轴数据相关属性
	 */
	getY_Fields : function() {
		var yAsix = Ext.getCmp("numerical").items.items;
		var _fromClause = {};
		var funValue;
		var array = new Array();
		for (var i = 0; i < yAsix.length; i++) {
			var seriesName = Ext.getCmp("sigma-number-btn" + yAsix[i].id).text;
			if (yAsix[i].attributes.customStyle == undefined || yAsix[i].attributes.customStyle == '') {
				funValue = yAsix[i].aggregate.name;
			} else {
				funValue = '';
			}
			array.push({
				"ID" : yAsix[i].attributes.columnId,
				"NAME" : yAsix[i].attributes.name,
				"FIELD_TYPE" : yAsix[i].attributes.dataType,
				"TABLENAME" : yAsix[i].attributes.tableName,
				"TABLEID" : yAsix[i].attributes.tableId,
				"ORDER_TYPE" : "desc",
				"FUN" : funValue,
				"SERIAS_NAME" : seriesName,
				"DATAUNIT" : yAsix[i].attributes.dataUnit,
				"DECIMAL_PRECISION" : yAsix[i].attributes.decimalPrecision,
				"CUSTOM_STYLE" : yAsix[i].attributes.customStyle
			});

		}
		_fromClause.MAIN_TABLE = array;
		return _fromClause;
	},
	/**
	 * 获取输出字段ID列表
	 * @return {}
	 */
	getOutputColumnIds : function(){
		var btns = this.findAllColumnBtn();
		var outputs = [];
		for(var i = 0 ;i < btns.length ;i++){
			outputs.push(btns[i].attributes.id);
		}
		return outputs;
	},
	/**
	 * 将记录转换成anychart可识别的json数据
	 * @param {} rows 记录集
	 * @return {} 
	 */
	transformToAnychart : function( rows ){
		var configs = this.getSeriesConfig();
		//初始化 序列 seriesMap[序列]
		var seriesMap = {};
		for(var i = 0 ; i < rows.length; i++){
			var row = rows[i];
			
			//序列合并
			var series = [];
			for(var j = 0 ;j < configs.topAxis.length ; j++){
				series.push( row[ configs.topAxis[j].name ] );
			}
			var serieName = series.join("-");
			
			//轴字段合并
			var axiss = [];
			for(var j = 0 ; j < configs.leftAxis.length ; j++){
				axiss.push( row[ configs.leftAxis[j].name ] );
			}
			var axisName = axiss.join("-");
			
			//生成序列和点（point）数据
			seriesMap[serieName] = seriesMap[serieName] || 	{
				name  : serieName,
				point : []
			};
			seriesMap[serieName].point.push({
				name : axisName,
				y 	 : row[configs.measure]
			});
		}
		
		//组成完整的anychart data 数据
		var data = { series:[] };
		for(var p in seriesMap){
			data.series.push(seriesMap[p]);
		}
		
		return data;
	},
	/**
	 * 获取序列配置
	 * @return {}
	 */
	getSeriesConfig : function(){
		//指标取值从sigma_value
		this.serieCfg.measure = biAnaly.SIGMA_VALUE;// int
		//横坐标
		this.serieCfg.leftAxis = Ext.getCmp('axis-column').getColumnConfigs();//topAxis
		//纵坐标
		this.serieCfg.topAxis = Ext.getCmp('legend-column').getColumnConfigs();//leftAxis
		//数值
		this.serieCfg.numerics = Ext.getCmp('numerical').getColumnConfigs();
		
		return this.serieCfg;
	},
	/**
	 * 校验字段配置是否正确
	 * @return {Boolean}
	 */
	validate : function(type){
		if(type == 'circularGauge') {
			if(Ext.getCmp('axis-column').items.getCount()> 0) {
				Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_NotOptional);
				Ext.getCmp('axis-column').body.highlight();
				return false;
			}
			
			if(Ext.getCmp('numerical').items.getCount()< 2) {
				Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_AtLeastSelTwoVal);
				Ext.getCmp('numerical').body.highlight();
				return false;
			}
				
		} else {
			if(Ext.getCmp('numerical').items.getCount()==0){
				Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_selOneVal);
				Ext.getCmp('numerical').body.highlight();
				return false;
			}
			
			if(Ext.getCmp('axis-column').items.getCount()==0){
				Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_selOneAxleField);
				Ext.getCmp('axis-column').body.highlight();
				return false;
			}
		}
		
		
		/*if(Ext.getCmp('report-filter').items.getCount() > 0) {
			var itemNum = Ext.getCmp('report-filter').items.getCount();
			for(var i=0; i<itemNum; i++) {
				if(Ext.getCmp('report-filter').items.itemAt(i).aggregate==null) {
					Ext.Msg.alert('提示','请设置筛选条件值！');
					Ext.getCmp('axis-column').body.highlight();
					return false;
				}
			}
		}*/
		return true;
	},
	
	/**
	 * 删除月份筛选
	 */
	removeMonthFilter : function(){
		Ext.getCmp('report-filter').remove('month-filter-btn',true);
	},
	/**
	 * 获取查询月份
	 * @return {String}
	 */
	getMonth : function(){
		var monthBtn = Ext.getCmp('month-filter-btn');
		return monthBtn ? monthBtn.getMonth() : '';
	},
	/**
	 * 查找所有字段按钮，不包含∑ 数值按钮
	 * @return {}
	 */
	findAllColumnBtn : function(){
		return this.findByTypeExclude('columnbutton','sigma-number-btn');
	},
	/**
	 * 通过xtype查找除excludeId外组件
	 * @param {} xtype 
	 * @param {} excludeId 忽略的组件ID
	 * @param {} shallow
	 * @return {}
	 */
	findByTypeExclude : function(xtype, excludeId ,shallow){
        return this.findBy(function(c){
            return c.isXType(xtype, shallow) && c.id !== excludeId;//测试组件的类型
        });
    }
});

Ext.reg('piceditpanel', biAnaly.PicEditPanel);

/**
 * 字段编辑容器
 * @class biAnaly.ColumnPanel
 * @extends Ext.Panel
 * @author chenzhuangwei
 */
biAnaly.ColumnPanel = Ext.extend(Ext.Panel, {
	isNumerical : false,//∑ 数值 容器
	enabledrop : true,
	maxColumnCount : -1,
	layout: {
	    type:'vbox',
	    padding:'1',
	    align:'stretch'
	},
	/**
	 * 插入字段组件
	 * @param {} attributes
	 */
	addColumn : function(attributes, panel){
		//如果是维字段，加载维数据
		/*if(attributes.colType == biAdhocNs.COLTYPE_DEMENSION){
			attributes.dimensionValues = biAnaly.getDemensionData(attributes.columnId);
		}*/
		/*type = (attributes.colType==biAdhocNs.COLTYPE_STAT_MON || 
					attributes.colType==biAdhocNs.COLTYPE_STAT_CIT) ? 
					'splitbutton' : 'columnbutton';
		if("report-filter" == panel.id) {
			type = 'splitbutton';
		}*/
		
		//添加 轴字段及∑数值  下组件，   add为同时添加图例字段系列下组件，其中轴字段下组件添加时，进行判断图例字段下组件不予添加
		var comp = this.add({     
			xtype: 'columnbutton',
			id : biAnaly.COLUMN_BTN_ID_PREFIX + attributes.id,
			text: attributes.cName,
			autoWidth:false,
			attributes : attributes
		});
		//判断是否有钻取路径，然后给标识赋值
		if (comp != null) {
			Ext.Ajax.request({
				url : [ biAdhocNs.sysUrl, 'chart/drillFlag' ].join(''),
				method : 'post',
				params : {
					name : comp.attributes.id, //即表中的name字段
					tableId : comp.attributes.tableName
				},
				callback : function(options, success, response) {
					var jsonObj = eval("("+response.responseText+")");
					if (jsonObj.drillList == "") { //是否存在钻取路径
						drillFlag = 0; 
					} else {
						drillFlag = 1;
					}
					comp.updateMenuItem();
				}
			});
		}
		
		//为组件名称添加前面的聚合函数的使用
		comp.updateAggregate();
		//组件名称显示赋值
		comp.updateCompText();
		//判断显示组件下按钮
		if(panel.id == 'axis-column'){
			xAsix = biAnaly.COLUMN_BTN_ID_PREFIX + attributes.id;  //   给轴字段变量赋值
		}
		this.doLayout();
	},
	/**
	 * 将组件移动到当前节点
	 * @param {} comp
	 */
	moveAt : function( comp ){  //由 图例字段 ，数值  组件拖过来的，分别删除对应容器中组件 
		if(this == comp.ownerCt)
			return;
		var lengend_panel=Ext.getCmp("legend-column");
		var numerical_panel=Ext.getCmp("numerical");
		if( comp.ownerCt == lengend_panel){
			var lengMove = Ext.getCmp(comp.id.substring(16, comp.id.length));
			
			this.add(lengMove);
			lengMove.updateAggregate();
			lengMove.updateCompText();
			lengMove.updateMenuItem();
			lengMove.syncSize();
			comp.removeSelf();
		}else{
			if( comp.ownerCt == lengend_panel){
				Ext.getCmp(biAnaly.COLUMN_BTN_ID_PREFIX+comp.id.substring(27,comp.id.length)).removeSelf();
			}
			if(comp.ownerCt == numerical_panel){
				Ext.getCmp('sigma-number-btn' + comp.id).removeSelf();
			}
			
			this.add(comp);
			comp.updateAggregate();
			comp.updateCompText();
			comp.updateMenuItem();
			comp.syncSize();
		}
		
		this.doLayout();
	},
	/**
	 * 是否可以插入新字段
	 * @param {} comp 将要插入组件
	 * @return {Boolean}
	 */
	isCanAddColumn : function(comp){
		//∑ 数值 Button 不可拖动到 ∑ 数值 Panel
		if(comp && comp.id.substring(0, 16) == 'sigma-number-btn' && this.isNumerical){
			Ext.qtip.error(columnpanel.alert_prompt, columnpanel.alert_notDragArea);
			return false;
		}
		if(this.maxColumnCount != -1 && this.items.getCount() >= this.maxColumnCount){
			Ext.Msg.alert(columnpanel.alert_prompt, this.title + columnpanel.alert_onlySelOne);//只能选择一个！
			return false;
		}
		/*if(this.id == 'legend-column'){
			Ext.qtip.error('提示', '使用图例字段时数值字段中只第一个有效，其他数值字段将被忽略！');
		}*/
		/*if(this.recommendColumnCount && this.items.getCount() >= this.recommendColumnCount ){
			Ext.qtip.msg('建议', this.title + '字段过多会导致图形复杂，建议设置' 
				+ this.recommendColumnCount + '个以内！');
		}*/
		return true;
	},
	/**
	 * 获取字段配置，包括name、cName
	 * 用于钻取的columnId,drillNodeId
	 * @return {}
	 */
	getColumnConfigs : function(){
		var cs = [];
		for(var i = 0 ; i < this.items.getCount(); i++){
			var item = this.items.itemAt(i);
			cs.push({
				name 		: item.getResultFieldName(),
				cName 		: item.getText(),
				//钻取信息
				//columnId 	: item.attributes.id,
				drillNodeId : item.attributes.drillNode ? item.attributes.drillNode.drillNodeId : undefined,
				drillLinkId : item.attributes.drillNode ? item.attributes.drillNode.drillLinkId : undefined
			});
		}
		return cs;
	},
	listeners : {
		render : function(panel){
			if(!this.enabledrop) return;
			var dropEl = panel.body.dom;
			var dt = new Ext.dd.DropTarget(dropEl, {
				ddGroup     : 'columnDDGroup',
				notifyEnter : function(ddSource, e, data) {
					panel.body.stopFx();
					panel.body.highlight();
				},
				notifyDrop  : function(ddSource, e, data){
					if(!panel.isCanAddColumn(data.comp))
						return;
					if(data.node){//从树节点拖动
						var comp = Ext.getCmp(biAnaly.COLUMN_BTN_ID_PREFIX + data.node.attributes.id);
						if( !comp ){//容器中没有此节点
							if(panel.id=="axis-column"&&data.node.attributes.colType==2){
								Ext.MessageBox.alert(columnpanel.alert_prompt,columnpanel.alert_xAxisCanNotIndex);//"x轴字段不能为指标！"
								return;
							}
								
								panel.addColumn(data.node.attributes, panel);
								Ext.getCmp('picturetree').setToggleCheck(data.node.attributes.id, true);
						}else{
							panel.moveAt(comp);
						}
					} else {//容器间拖动
						panel.moveAt(data.comp);
					}
					return true;
				}
			});
			//加入树节点的拖放组，支持对树节点的拖放操作
			dt.addToGroup('treeColumnDDGroup');
		},
		remove : function(panel, component){
			//刷新panel显示
			panel.doLayout();
		},
		add : function(panel, component, index) {
			if(panel.isNumerical){
				var legendPanel = Ext.getCmp('legend-column');
				legendPanel.add({
					xtype:'columnbutton',
					id : 'sigma-number-btn' + component.id,
					text: component.text,
					attributes : {//数值按钮的固定属性
						name : biAnaly.SIGMA_NAME,
						dataType : 'string'
					},
					menu:{
						items : [{
							text : columnpanel.text_delete,//删除
							handler : function(item) {
								Ext.getCmp('picturetree').setToggleCheck(component.attributes.id,false);
							}
						},{  
	                        text: columnpanel.title_Edit,//'编辑'
	                        handler:function (item){
	                        	var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
	        					comp.ownerCt.ownerCt.columnEditTooltip.show();
	        					comp.ownerCt.ownerCt.columnEditTooltip.setParentBtn(comp);
	        					
	                        }  
	                    } ]
					},
					updateMenuItem : function(){}
				});
				legendPanel.doLayout();
			}
		}
	}
});

Ext.reg('columnpanel', biAnaly.ColumnPanel);

/**
 * 字段按钮
 * @class biAnaly.ColumnButton
 * @extends Ext.SplitButton
 * @author chenzhuangwei
 */
biAnaly.ColumnButton = Ext.extend(Ext.SplitButton, {
	template : new Ext.Template(
	    '<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
	    '<tr><td class="x-btn-tl x-btn-tl-3"><i>&#160;</i></td><td class="x-btn-tc x-btn-tc-3"></td><td class="x-btn-tr x-btn-tr-3"><i>&#160;</i></td></tr>',
	    '<tr><td class="x-btn-ml x-btn-ml-3"><i>&#160;</i></td><td class="x-btn-mc x-btn-mc-3"><em class="{2}" unselectable="on"><button type="{0}"></button></em></td><td class="x-btn-mr x-btn-mr-3"><i>&#160;</i></td></tr>',
	    '<tr><td class="x-btn-bl x-btn-bl-3"><i>&#160;</i></td><td class="x-btn-bc x-btn-bc-3"></td><td class="x-btn-br x-btn-br-3"><i>&#160;</i></td></tr>',
	    '</tbody></table>'),
	attributes : {},//null,
	isAggregate : '0',		//是否聚集 0:为不聚集 1:聚集
	aggregate : null,		//聚集设置（值字段设置）
	autoWidth:false,
	listeners :{
		afterrender : function (btn){
		    btn.dragZone = new Ext.dd.DragZone(btn.getEl(), {
				ddGroup     : 'columnDDGroup',
		        getDragData: function(e) {
		            var sourceEl = e.getTarget('table.x-btn', 10);
		            if (sourceEl) {
		                d = sourceEl.cloneNode(true);
		                d.id = Ext.id();
		                return btn.dragData = {
		                    sourceEl: sourceEl,
		                    repairXY: Ext.fly(sourceEl).getXY(),
		                    ddel: d,
		                    comp : Ext.getCmp(sourceEl.id)
		                };
		            }
		        },
		        getRepairXY: function() {
		            return this.dragData.repairXY;
		        }
		    });
		}
	},
	menu : {
		items : [{
			text : columnpanel.text_delete,//'删除'
			handler : function(item) {
				var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
				//通知树节点，字段已删除
				Ext.getCmp('picturetree').setToggleCheck(comp.attributes.id,false);
				if(Ext.getCmp('condition-edit')!=null){
					Ext.getCmp('condition-edit').hide();
					biAdhocNs.conditionFilterObj.closeAllTip();
				}
			}
		},{
			text : columnpanel.text_valueSet,//'值字段设置'
			handler : function(item){
				var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
				comp.ownerCt.ownerCt.columnCfgTooltip.show();
				comp.ownerCt.ownerCt.columnCfgTooltip.setParentBtn(comp);
			}
		},{
			text : columnpanel.text_conditionSet,//'筛选条件设置'
			hidden : false ,//默认不显示
			handler : function(item){
				// var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
				// comp.ownerCt.ownerCt.columnFilterTooltip.setParentBtn(comp);
				// comp.ownerCt.ownerCt.columnFilterTooltip.show();
				biAdhocNs.conditionFilterObj.filterConditionEdit(item.parentMenu.ownerCt.id);
			}
		},{
			text : columnpanel.text_drillSet,//'钻取设置'
			handler : function(item){
				// 获取button控件
				var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
				var drillStore = new Ext.data.Store({
					baseParams : {
						columnId : comp.attributes.columnId,
						drillPath : ''
					},
					reader : new Ext.data.JsonReader({
						root : 'drillList',
						fields : ['columnId', 'cnamePath', 'drillPath', 'namePath']
					}),
					proxy : new Ext.data.HttpProxy({
						url : [ biAdhocNs.sysUrl,
								'chart/drillValue' ].join('')
					})
				});
				
				var rowSelMod = new Ext.grid.RowSelectionModel({//定义单行选择
					singleSelect : true
				});

				var drillTooltip = comp.ownerCt.ownerCt.columnDrillTooltip;
				// 创建 Grid 对象
				var grid = new Ext.grid.GridPanel({
					id : 'drill-select-grid',
					store : drillStore,
					cls : 'panel-margin',
					border : false,
					selModel : rowSelMod,
					columns : [{
						header : columnpanel.header_drillName,//'名称'
						hideable : false,
						hidden : true,
						dataIndex : 'columnId'
					}, {
						header : columnpanel.header_drillPath,//'钻取路径'
						dataIndex : 'cnamePath',
					}],
					stripeRows : true,
					height : 300,
					loadMask : true,
					stateful : true,
					enableHdMenu : false,
					viewConfig : {
						forceFit : true
					},
					fbar : [{
						text : columnpanel.text_ok,
						iconCls : 'icon-confirm',
						handler : function() {
							if(grid.getSelectionModel().selections.length==0){
//								rowSelMod.selectFirstRow();
								Ext.Msg.alert(columnpanel.alert_prompt,columnpanel.alert_selOneRow);//请先选择一行数据
							}else{
								var drillData = grid.getSelectionModel().selections.items[0].json;
								var btn = Ext.getCmp(biAnaly.COLUMN_BTN_ID_PREFIX + comp.attributes.id); 
								btn.setText(drillData.cnamePath);
								btn.attributes.text = drillData.drillPath;
								btn.namePath = drillData.namePath;
								drillTooltip.hide();
							}
						}
					}, {
						text : columnpanel.text_close,//'关闭'
						iconCls : 'icon-full-select',
						handler : function() {
							drillTooltip.hide();
						}
					}, {
						xtype : 'label',
						html : '<div style="width:125px"></div>',
						disabled : true
					}]
				});
				// 设置钻取设置界面的grid为新建的grid
				drillTooltip.grid = grid;
				// 加载钻取路径
				drillStore.load();
				drillTooltip.show();
			}
		},{
			text : columnpanel.text_cancelDrill,//'取消钻取'
			handler : function(item){
				// 获取button控件
				var comp = Ext.getCmp(item.parentMenu.ownerCt.id);
				var btn = Ext.getCmp(biAnaly.COLUMN_BTN_ID_PREFIX + comp.attributes.id); 
				var btnText = Ext.getCmp("axis-column").items.items[0].attributes.cName;
				if (columnButtonText != "") {
					btn.setText(btnText);
					btn.attributes.text = columnButtonAttrText;
					btn.namePath = columnBtnNamePath;
				}
			}
		}]
	},
	
	/**
	 * 设置聚集函数
	 * @param {} agg
	 */
	setAggregate : function(agg){
		if(agg){
			this.isAggregate = '1';
			this.aggregate = agg;
		} else {
			this.isAggregate = '0';
			this.aggregate = null;		
		}
	},
	/**
	 * 更新组件Text_lengend by ghq 2014年1月15日19:18:19   
	 */
	setText_lengdend : function(object){
			this.setText(object);
	},
    
	/**
	 * 更新组件Text
	 */
	updateCompText : function(id){
		if(this.aggregate){
			this.setText(this.aggregate.description + '：' + this.attributes.text);
		} else {
			this.setText( this.attributes.cName || this.getText());
			columnButtonText = this.getText();
			columnButtonAttrText = this.attributes.text;
			columnBtnNamePath  = this.namePath;
		}
	},
	/**
	 * 更新菜单项显示
	 */
	updateMenuItem : function(){
		if(this.ownerCt.isNumerical) {   //y轴下组件显示
		// if(this.ownerCt.isNumerical){
			this.menu.items.itemAt(0).show();
			this.menu.items.itemAt(1).show();
			this.menu.items.itemAt(2).hide();
			this.menu.items.itemAt(3).hide();
			this.menu.items.itemAt(4).hide();
		} else if(this.ownerCt.id == "report-filter") { //报表筛选 组件显示
			this.menu.items.itemAt(0).show();
			this.menu.items.itemAt(1).hide();
			this.menu.items.itemAt(2).show();
			this.menu.items.itemAt(3).hide();
			this.menu.items.itemAt(4).hide();
		} else {								//轴字段(分类) 组件显示
			this.menu.items.itemAt(0).show();
			this.menu.items.itemAt(1).hide();
			this.menu.items.itemAt(2).hide();
			if (drillFlag == 1) {
				this.menu.items.itemAt(3).show();
				this.menu.items.itemAt(4).show();
			} else if (drillFlag == 0) {
				this.menu.items.itemAt(3).hide();
				this.menu.items.itemAt(4).hide();
			}
		}
	},
	/**
	 * 更新字段聚合函数
	 */
	updateAggregate : function(){
		//数值类型使用聚集函数
		if(this.ownerCt.isNumerical){
			if(this.attributes.dataType.toUpperCase()=='INTEGER' || 
				this.attributes.dataType.substr(0, 6).toUpperCase()=='NUMBER'){
				this.setAggregate({
					name : 'sum',
					description : columnpanel.text_sum
				});
			}else{
				this.setAggregate({
					name : 'count',
					description : columnpanel.text_count
				});
			}
		}else{
			this.setAggregate(null);
		}
	},
	removeSelf : function(){
		this.ownerCt.remove(this.id, true);
	},
	/**
	 * 获取结果字段名，默认返回当前字段名，维时返回对应维字段名
	 * @return {}
	 */
	getResultFieldName : function(){
		var attr = this.attributes;
		return (attr.colType == biAdhocNs.COLTYPE_DEMENSION  && attr.textColName != '' ) ?
				attr.textColName.toLowerCase() : attr.name.toLowerCase();
	},
	/**
	 * 获取 SQL 表达式
	 * @return {}
	 */
	getExpValue : function(){
		var v = this.attributes.table.tableAsName + '.' + this.attributes.name;
		//维
		if(this.attributes.colType == biAdhocNs.COLTYPE_DEMENSION 
			&& this.attributes.asName != '' 
			&& this.attributes.textColName != '' ) {
			v = this.attributes.asName+"."+this.attributes.textColName;
		}
		//聚集
		if(this.ownerCt.isNumerical && this.isAggregate == '1'){
			v = this.aggregate.name + '(' + v + ')';
		}
		return v;
	},
	/**
	 * 获取sql语句中select 部分
	 * @return {}
	 */
	getSelectField : function(){
		if(this.attributes){
			var attr = this.attributes;
			return {
				ID : attr.id, 							//字段ID
				EXP_VALUE : this.getExpValue(),			//字段表达式
				EXP_CVALUE : attr.cName ,				//字段表达式
				NODE_TYPE : attr.colType,				//节点类型
				TABLE_NAME : attr.table.tableName,		//表名
				IS_SENSITIVE : attr.isDelicate,			//是否敏感字段 0:否 1:是
				PART_TYPE : attr.table.tablePartType,	//分区类型
				EDITED_OPER_FLAG: this.isAggregate,		//该字段是否被编辑过
				IS_AGGREGATE : this.isAggregate,		//是否聚集 0:为不聚集 1:聚集
				FILED_NAME : attr.name,					//字段名称
				ALIAS : attr.asName						//字段别名
			};
		}
		return null;
	},
	getGroupBy : function(){
		if(this.attributes && this.isAggregate == '0'){
			var attr = this.attributes;
			return {
				ID : attr.id,							//字段ID
				NODE_TYPE : attr.colType,				//节点类型
				EXP_VALUE : this.getExpValue(),			//分组表达式
				EXP_CVALUE : attr.cName,				//分组表达式中文描述
				TABLE_NAME : attr.table.tableName,		//表名
				FIELD_NAME : attr.name,					//字段名称
				PART_TYPE : attr.table.tablePartType	//分区类型 //分区类型 按月分表的类型:2:按地市分表 3:按地市按月分表
			};
		}
		return null;
	}
});

Ext.reg('columnbutton', biAnaly.ColumnButton);


/**
 * 分块工具条
 * @class biAnaly.BlockingToobar
 * @extends Ext.PagingToolbar
 * @author chenzhuangwei
 */
biAnaly.BlockingToobar = Ext.extend(Ext.PagingToolbar, {
	displayMsg : '分块字段：<font color="red">{3}</font> ',//| 当前记录块: {0} - 总记录块数: {2}
	emptyMsg : '没有可显示的数据',
	beforePageText : '当前块',
	afterPageText : '总块数: {0}',
	firstText : '第一块',
	prevText : '前一块',
	nextText : '下一块',
	lastText : '最后一块',
	refreshText : '刷新',
	displayInfo : true,
	block : null,
	initComponent : function(){
	  	biAnaly.BlockingToobar.superclass.initComponent.call(this);
	  	
	  	this.goBnt = new Ext.Button({
			id : 'go-bnt',
			iconCls : 'execute-go-icon',
			tooltip : 'GO',
			handler : this.handClick,
			scope: this
		 });
	  	this.insert(5,this.goBnt);
	  	this.refresh.setDisabled(true);
	},
	handClick : function(){
		pageNum = this.readPage({activePage:this.cursor});
		if(pageNum !== false && this.block){
			this.doLoad(Math.min(pageNum,this.block.totalBlocks));
		}
	},
	updateInfo : function(){
        if(this.displayItem){
            var count = this.block.totalBlocks;
            var msg = count == 0 ?
                this.emptyMsg :
                String.format(
                    this.displayMsg,
                    this.cursor, this.cursor+count, count,this.block.blockDimens[4]||''
                );
            this.displayItem.setText(msg);
        }
    },
    /**
     * 绑定分块信息
     * @param {} blockingInfo
     */
    bind : function(blockingInfo){
    	this.blockingInfo = blockingInfo;
    	this.doLoad(1);
    },
    doLoad : function(start){
    	this.block.activeBlock = start;
    	this.cursor = start;
    	var dl = pictureAnalyze.getDrillManager().getDrillAtBlocking();
    	biAnaly.picHandler(this.block , dl);
    },
    setBlock : function(block ){
    	this.block = block;
    		
        var ap = this.cursor = this.block.activeBlock;
        var ps = this.block.totalBlocks;
        
        this.afterTextItem.setText(String.format(this.afterPageText, ps));
        this.inputItem.setValue(ap);
        this.first.setDisabled(ap == 1);
        this.prev.setDisabled(ap == 1);
        this.next.setDisabled(ap == ps);
        this.last.setDisabled(ap == ps);
        this.refresh.enable();
        this.goBnt.enable();
        this.updateInfo();
    },
    disabledAllBtn : function(){
    	this.first.setDisabled(true);
        this.prev.setDisabled(true);
        this.next.setDisabled(true);
        this.last.setDisabled(true);
        this.refresh.setDisabled(true);
        this.goBnt.setDisabled(true);
    },
    getBlock : function(){
    	return this.block;
    },
    onPagingKeyDown : function(field, e){
    	/*var k = e.getKey(),pageNum;
    	if (k == e.RETURN) {
			pageNum = this.readPage({activePage:this.cursor});
			if(pageNum !== false){
                this.doLoad(Math.min(pageNum,this.block.totalBlocks));
            }
        }*/
    },
    onPagingBlur : function(e){
    },
    moveFirst : function(){
        this.doLoad(1);
    },
    movePrevious : function(){
    	this.doLoad(this.cursor - 1);
    },
    moveNext : function(){
    	this.doLoad(this.cursor + 1);
    },
    moveLast : function(){
    	this.doLoad(this.block.totalBlocks);
    },
    doRefresh : function(){
        this.doLoad(this.cursor);
    }
});
Ext.reg('uc_blocking', biAnaly.BlockingToobar);


/**
 * 数据旋转用于将指标记录拆分，重组记录集的数据结构
 * @class biAnaly.RecordPivot
 * @author chenzhuangwei
 */
biAnaly.RecordPivot = function(){
	return {
		/**
		 * 数据旋转
		 * @param {} rows 数据
		 * @param {} numerics 数值（指标）字段列表
		 * @param {} convert 修改数据的属性名称 convert[srcColumn] = destColumn 
		 * @return {}
		 */
		pivot : function(rows,numerics,convert){
			var datas = [];
			//迭代原始数据对每条记录进行旋转
			for(var i = 0 ; i < rows.length ; i++ ){
				var row = rows[i];
				//迭代要旋转的每个字段
				for(var j = 0 ; j < numerics.length ; j++ ){
					var data = {};
					//拷贝记录中所有字段
					for(var p in row){
						//修改属性名称
						if(convert && convert[p]){
							data[convert[p]] = row[p];
						}else{
							data[p] = row[p];
						}
					}
					//加入旋转后的字段属性
					data[ biAnaly.SIGMA_NAME ] = numerics[j].cName;
					data[ biAnaly.SIGMA_VALUE ] = row[ numerics[j].name ];
					datas.push(data);
				}
			}
			
			//删除多余属性
			for(var i = 0 ; i < datas.length ;i++){
				var data = datas[i];
				for(var j = 0 ; j < numerics.length ; j ++){
					delete data[numerics[j].name];
				}
			}
			return datas;
		}
	}
}();


